<script>
import _ from 'lodash'
import dataObjectConf from '../data-object-conf.js'
import { getUiItemDataObject, generateOperateButtons } from '../mixins.js'

const getTextareaDataObject = (setting = {}, editable) => {
  return _.merge({
    props: { readonly: editable }
  }, dataObjectConf, {
    props: {
      type: 'textarea',
      placeholder: setting.options.placeholder,
      value: setting.options.defaultValue
    }
  })
}

export default {
  name: 'InputAdapter',
  props: [
    'setting',
    'editable',
    'selected'
  ],
  functional: true,
  render (h, context) {
    const editable = context.props.editable
    const extra = editable
      ? generateOperateButtons(h, context)
      : []
    return h('FormItem', getUiItemDataObject(context), [
      h('Input', getTextareaDataObject(context.props.setting, editable)),
      ...extra
    ])
  }
}
</script>
